<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="/publico/template.xhtml">
        <ui:define name="content">
            <h:form id="fcardapio">
                <p:panel header="Tabela de Cardápios">
                    <h4 style="margin: 0.8em 0">Exportar para PDF ou Excel</h4>

                    <p:commandLink id="pdf" ajax="false" title="Exportar dados da tabela para PDF">
                        <h:graphicImage library="icons" name="pdf-48.png"/>
                        <pe:exporter type="pdf" target="dt-cardapio" fileName="cardápio" encoding="iso-8859-1"/>
                    </p:commandLink>  

                    <p:commandLink id="xlsx" ajax="false" title="Exportar dados da tabela para Excel">
                        <h:graphicImage library="icons" name="excel-48.png"/>
                        <pe:exporter type="xlsx" target="dt-cardapio" fileName="cardápio" encoding="iso-8859-1"/>
                    </p:commandLink>

                    <p>
                        <p:button id="cbnovo"
                                  class="btn-a-esquerda"
                                  value="Novo"
                                  outcome="/admin/cardapio/cardapio.xhtml"
                                  icon="ui-icon-plus"/>
                    </p>

                    <p:dataTable id="dt-cardapio" 
                                 value="#{cardapioBean.cardapios}"
                                 var="cardapio"
                                 paginator="true"
                                 rows="10"
                                 expandedRow="true"
                                 emptyMessage="sem dados">
                        <f:facet name="header">
                            <h:outputText value="Cardápios"/>
                        </f:facet>

                        <p:column>
                            <h:outputText value="#{cardapio.nome}"/>
                        </p:column>

                        <p:column width="55" class="center">
                            <p:commandButton id="cb-editar"
                                             ajax="false"
                                             action="/admin/cardapio/cardapio.xhtml"
                                             icon="ui-icon-pencil">
                                <f:setPropertyActionListener 
                                    target="#{cardapioBean.cardapio}" 
                                    value="#{cardapio}"/>
                            </p:commandButton>
                        </p:column>

                        <p:column width="55" class="center">
                            <p:commandButton id="cb-excluir"
                                             ajax="false"
                                             icon="ui-icon-trash"
                                             onclick="return confirm('Você tem certeza?')"
                                             action="#{cardapioBean.excluir()}">
                                <f:setPropertyActionListener 
                                    target="#{cardapioBean.cardapio}" 
                                    value="#{cardapio}"/>
                            </p:commandButton>
                        </p:column>

                        <p:rowExpansion>
                            <p:dataTable id="dt-itens"
                                         value="#{cardapio.itens}"
                                         var="item"
                                         emptyMessage="sem registros">
                                <p:column>
                                    <h:outputText value="#{item.nome}"/>
                                </p:column>
                            </p:dataTable>
                        </p:rowExpansion>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
